<script type="text/javascript">
//禁止输入中文汉字
	function isSpecialChar(id){
		var iptData=document.getElementById(id);
		if(iptData.value.match(/[^\x00-\xff]/ig)){
		iptData.value=iptData.value.replace(/[^\x00-\xff]/ig,"");
		}
	}
</script>
	<div class="block">
<div class="invertedshiftdown">
		
		<ul>
			<li class="current"><a href="?page=manage_users">用户管理</a></li>
			<li><a href="?page=manage_organizations">机构管理</a></li>
			<li><a href="?page=manage_items">产品管理</a></li>
            <li><a href="?page=manage_stack">下达入库指令</a></li>
			<li><a href="?page=manage_transaction">撤销错误记录（慎用）</a></li>
 		</ul>




		<form id="myform">
			<input type="text" class="textinput" /> <input class="submit" type="submit" value="搜索" />
		</form>
	</div>
	<br style="clear: both;" />
<div id= 'content'>
	<h2>管理菲雪》用户管理</h2>
	
		<?php
	//print_r($_GET);
	if(isset($_GET['stat'])){
		if($_GET['stat']=='added'){
	?>
	<div class="isa_success">
		<h4>操作成功：</h4>添加用户
	</div>
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='add'){
	?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法添加该用户
	</div>
	<?php
		}elseif($_GET['stat']=='deleted'){
	?>
	<div class="isa_success">
		<h4>操作成功：</h4>删除用户
	</div>
	<?php
		}elseif($_GET['stat']=='altered'){
	?>
	<div class="isa_success">
		<h4>操作成功：</h4>更改用户
	</div>
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='missing'){
	?>
	<div class="isa_error">
		<h4>操作失败：</h4>缺省必要信息
	</div>
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='format'){
	?>
	<div class="isa_error">
		<h4>操作成功：</h4>无法更新图片 图片格式不符合标准 （jpeg 或者 jpg）
	</div>
		<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='unlink'){
	?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法更新图片 无法删除已有图片
	</div>
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='unknown'){
	?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法更新图片 未知问题
	</div>
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='unlink'){
	?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法添加/更改图片（提交了无效数据）
	</div>
<?php

		}
}
	?>

	<table class="contentTable" border="1">
			<tbody><tr class="solid">
		<td>帐号/在线</td>
		<td>基本信息</td>
		<td>帐户信息</td>
		<td>平台信息</td>
		<td>操作</td>
		<td>头像</td>
		</tr>
	
	
		<?php
		foreach($allUsers as $user){
		?>
		<tr>
		<td><?php
		if($user->id==$currentUser->id){
		echo "<div class='online stat'> $user->id</div>";
		}else{
		 if(in_array($user->id,$online)){
			echo "<div class='online' onclick='chatwith($user->id)'> $user->id</div>";
		 }else{
		 echo "<div class='offline stat' onclick='chatwith($user->id)'> $user->id</div>";
		 }
		  }
		 ?>
		
			
		</td>
		<td>	
			<ul class="manage_user">
				<li>真实姓名：<?php echo $user->real_name;?></li>
				<li>邮箱：<?php echo $user->email;?></li>
				<li>电话号码：<?php echo $user->phone_number;?></li>
				<li>工作地址：<?php echo $user->work_address;?></li>
			</ul>
	    </td>
		<td>
			<ul class="manage_user">
				<li>用户名：<?php echo $user->name;?></li>
				<li>权限：<?php echo $user->getAuthorityName();?></li>
				<li>职位：<?php echo $user->position;?></li>
		
				
			</ul>
		</td>
		<td>
			<ul class="manage_user">
				<li>IP地址：<?php echo $user->ip;?></li>
				<li>操作系统：<?php echo $user->os;?></li>
				<li>浏览器：<?php echo $user->browser;?></li>
			</ul>
		</td>

	
	<td>
			 <form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="delete_user" />
            <input type="hidden" id='id' name="id" value=<?php echo $user->id;?> />

	
	<?php 
	if($user->id==$currentUser->id){
	?>
	<input type="submit" value="删除" style="float:left" disabled/><div class="important">自身帐号不可删除</div>

	<?php 
	}elseif($user->authrized('management')){
	?>
		<input type="submit" value="删除" style="float:left" disabled/><div class="important">此账户为管理员 管理员帐号不可被删除</div>

	<?php
	}else{
	?>
<input type="submit" value="删除"/>
<?php
	}
?>
          </form>
          
          
          <form action="index.php" method="GET">
          	            <input type="hidden" id='id' name="id" value=<?php echo $user->id;?> />
          	            <input type="hidden" id='page' name="page" value='alter_user'/>
	
	<?php 
	if($user->id==$currentUser->id){
	?>
	<input type="submit" value="更改" style="float:left" disabled/><div class="important">请到“帐户详情”更改</div>

	<?php 
	}elseif($user->authrized('management')){
	?>
		<input type="submit" value="更改" style="float:left" disabled/><div class="important">此账户为管理员 权限不可被修改</div>

	<?php
	}else{
	?>
<input type="submit" value="更改"/>
<?php
	}
?>

</form>
		</td>
			<td>
	<?php
    		if(file_exists('images/user/'.$user->id.'.jpg')){
    		?>
    		<img id="blah" src="<?php echo 'images/user/'.$user->id.'.jpg'?>" alt="userImage" style=" padding:10px;height:100px;weight:100px"/>
    		<?php
			}else{
    		?>
    		<img id="blah" src="images/user/default.jpeg" alt="userImage" style="height:100px;weight:100px;padding:10px"/>
    		<?php
			}
    		?>
	</td>
		</tr>

	
	<?php
		}
	?>
		</tbody></table>
<br>
<br>
<br>
<div></div>

    <div class="form">
    	<b>添加用户</b>
        <form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="add_user" />
    <div class="element">
        <label class="form">用户名(字母和数字)</label>
 
        <input type="text" id="name" name="name" class="text" value='' onkeyup="isSpecialChar(this.id)"><p class='important'>*必须</p>
    </div> 
    <div class="element" style="clear:both;">
        <label class="form">权限</label>
        
        <div class='checkbox'>
        	
    <input type="radio" name="authority" value="none">无权限 (学员，仅开放有限的略览权限)<br>
    <input type="radio" name="authority" value="pick" checked="checked">选择 (可多选)<br>
    <div>
    <?php
    foreach($allOrganizations as $organization){
    		$organization->name;
	?>
	    <input type="checkbox" name="pick[]" value="<?php echo $organization->id;?>"><?php echo $organization->name;?><br>
		
	<?php	
    }
    ?>
        <input type="checkbox" name="pick[]" value="management">管理<br>
	    <input type="checkbox" name="pick[]" value="accounting">财务/会计<br>

    </div>
     </div>

    </div>
    <div class="element">
        <label class="form">密码（字母和数字）</label>
        <input type="text" id="password" name="password" class="text" value='1111' disabled>
    </div>
    <div class="element">
        <label class="form">真实姓名（中文）</label>
 
        <input type="text" id="real_name" name="real_name" class="text" value='' >
    </div>
    <div class="element">
        <label class="form">邮箱</label>
 
        <input type="text" id="email" name="email" class="text" value='' >
    </div>
    <div class="element">
        <label class="form">电话号码（数字）</label>
 
        <input type="text" id="phone_number" name="phone_number" class="text" value='' >
    </div>
    <div class="element">
        <label class="form">工作地址</label>
 
        <input type="text" id="work_address" name="work_address" class="text" value='' >
    </div>

 

    <div class="element">
<input type="submit" value="递交" />
        <div class="loading"></div>
    </div>
    </form>
    </div>
  
    </div>
    </div>
<div class="clear"></div>
	</div>